package com.bw.sign

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.SPUtils
import com.bw.lib_base.entity.SignBean
import com.bw.lib_base.entity.SignBeanItem
import com.bw.lib_base.mvvm.BaseActivity
import com.bw.sign.databinding.ActivitySignHistoryBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/sign/SignHistoryActivity")
class SignHistoryActivity : BaseActivity<ActivitySignHistoryBinding,SignViewModel>() {
    val signAdapter by lazy { SignAdapter() }
    var all:MutableList<SignBeanItem> ?= null
    override fun initView() {
        binding.rvSign.apply {
            adapter = signAdapter
            layoutManager = LinearLayoutManager(this@SignHistoryActivity)
        }


        binding.rgSign.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId){
                R.id.sign_zc ->{
                    filter("正常")
                }
                R.id.sign_cd ->{
                    filter("迟到")
                }
                R.id.sign_zt ->{
                    filter("早退")
                }
                R.id.sign_qq ->{
                    filter("缺勤")
                }
                R.id.sign_all ->{
                    viewModel.history(SPUtils.getInstance().getInt("uid"))
                }
            }
        }
    }

    override fun initData() {
        viewModel.hisData.observe(this){
            signAdapter.addData(it)
            all = it
            signAdapter.notifyDataSetChanged()
        }
    }

    fun filter(status: String){
        val list = all?.filter { it.status == status }
        signAdapter.data.clear()
        signAdapter.addData(list!!)
        signAdapter.notifyDataSetChanged()
    }

    override fun onResume() {
        super.onResume()
        viewModel.history(SPUtils.getInstance().getInt("uid"))
    }
}